/**
 * Yolema.com Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */
package org.grayrabbit.pay.core.service.transaction.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.grayrabbit.pay.core.model.pages.PageList;
import org.grayrabbit.pay.core.model.pages.PageTools;
import org.grayrabbit.pay.core.service.transaction.TradeRecordService;
import org.grayrabbit.pay.core.dao.transaction.TradeRecordDao;
import org.grayrabbit.pay.core.model.entity.transaction.TradeRecord;

/**
 * 
 * 
 * @author liyd
 * @version $Id: TradeRecordServiceImpl.java, v 0.1 Thu May 31 14:50:37 CST 2012 liyd Exp $
 */
@Component
public class TradeRecordServiceImpl implements TradeRecordService {

    @Autowired
    private TradeRecordDao tradeRecordDao;

    /**
     * 查询业务对象列表
     * 
     * @param tradeRecord
     * @return
     */

    public PageList<TradeRecord> queryPageList(TradeRecord tradeRecord) {

        PageTools pageTools = new PageTools();
        pageTools.setPage(tradeRecord.getPageNum());
        pageTools.setItemsPerPage(tradeRecord.getPageSize());

        Map<String, Object> params = new HashMap<String, Object>();

        params.put("query", tradeRecord);
        params.put("startRow", pageTools.getBeginIndex());
        params.put("pageSize", pageTools.getItemsPerPage());

        pageTools.setItems(tradeRecordDao.queryCount(params));

        PageList<TradeRecord> pageList = new PageList<TradeRecord>();
        pageList.addAll(tradeRecordDao.queryPageList(params));
        pageList.setPageTools(pageTools);

        return pageList;

    }

    /**
     * 根据Id得到实体对象
     * 
     * @param id
     * @return
     */
    public TradeRecord getById(Long id) {

        return tradeRecordDao.getById(id);
    }

    /**
     * 根据id批量删除
     * 
     * @param idArray
     */
    public void deleteBatchById(Long[] idArray) {
        tradeRecordDao.deleteBatchById(idArray);
    }


    /**
     * 添加一个对象
     * 
     * @param tradeRecord
     */
    public void insert(TradeRecord tradeRecord) {

        tradeRecordDao.save(tradeRecord);

    }

    /**
     * 更新一个对象
     * 
     * @param tradeRecord
     * @return
     */
    public int update(TradeRecord tradeRecord) {

        return tradeRecordDao.update(tradeRecord);

    }

    /**
     * 删除一个对象
     * 
     * @param tradeRecord
     */
    public void delete(TradeRecord tradeRecord) {
        tradeRecordDao.delete(tradeRecord);
    }

    @Override
    public List<TradeRecord> getBySystemId(Long systemId) {
        return tradeRecordDao.getBySystemId(systemId);
    }

    @Override
    public List<TradeRecord> queryList(TradeRecord tradeRecord) {
        return tradeRecordDao.queryList(tradeRecord);
    }

}
